//修改密码组件
Vue.component('edit_password', {
	template: '<div class="password one_type">\
					<li class="type_title">修改密码</li>\
					<form id="editPwda" class="form-horizontal">\
					 <div class="form-group">\
					    <label for="inputPassword3" class="col-sm-3 control-label">旧密码</label>\
					    <div class="col-sm-6">\
					      <input name="oldPwd" type="password" v-model="oldPwd" class="form-control" id="inputPassword3" placeholder="旧密码">\
					    </div>\
					  </div>\
					  <div class="form-group">\
					    <label for="inputPassword3" class="col-sm-3 control-label">新密码</label>\
					    <div class="col-sm-6">\
					      <input name="newPwd" type="password" v-model="newPwd" class="form-control" id="inputPassword3" placeholder="新密码">\
					    </div>\
					  </div>\
					  <div class="form-group">\
					    <label for="inputPassword3" class="col-sm-3 control-label">确认密码</label>\
					    <div class="col-sm-6">\
					      <input name="confirmPwd" type="password"  v-model="confirmPwd" class="form-control" id="inputPassword3" placeholder="确认密码">\
					    </div>\
					  </div>\
					  <div class="form-group">\
					    <div class="col-sm-offset-3 col-sm-6">\
					      <button type="button" class="btn btn-base" v-on:click="editPwda">确定</button>\
					    </div>\
					  </div>\
					</form>\
				</div>',
	data: function() {
		return {
			oldPwd: "",
			newPwd: "",
			confirmPwd: "",
			url: {
				//modifyPwd:'/api/UserInfo/ModifyPwd',
				modifyPwd: '/api/UserInfo/ModifyPwd2',
			}
		}
	},
	mounted: function() {
		console.log(globalData.userInfo);
		setTimeout(function(){			
			$('#editPwda').bootstrapValidator(edit_password_valid_json);
		},100)
	},
	methods: {
		editPwda: function() {
			$('#editPwda').bootstrapValidator('validate');
			var b = $('#editPwda').data("bootstrapValidator").isValid();
			if(!b){
				return;
			}
		
			data = {
				'NewPassword': this.newPwd,
				'OldPassword': this.oldPwd
			}
			globalData.ajaxPost(this.url.modifyPwd, data, function(res) {
				if(res.suc) {
					globalData.utils.alert("修改密码成功",function(){
						window.location.reload()
					});				
				} else {
					globalData.utils.alert(res.msg);
				}
			});
			
		}
	}
});

var edit_password_valid_json = {
	message: 'This value is not valid',
	feedbackIcons: {
		valid: 'glyphicon glyphicon-ok',
		invalid: 'glyphicon glyphicon-remove',
		validating: 'glyphicon glyphicon-refresh'
	},
	fields: {
		oldPwd: {
			validators: {
				notEmpty: {
					message: '旧密码不能为空'
				}
			}
		},
		newPwd: {
			validators: {
				notEmpty: {
					message: '新密码不能为空'
				}
			},
			stringLength: {
                min: 6,
                message: '密码长度不少于6'
            }
		},
		confirmPwd: {
			validators: {
				notEmpty: {
					message: '确认密码不能为空'
				},
				stringLength: {
                    min: 6,
                    message: '密码长度不少于6'
                },
				identical: {
					field: 'newPwd',
					message: "两次输入的密码不一致"
				}
			}
		}
	}
}